<!--
 * @Author: your name
 * @Date: 2022-08-11 11:48:59
 * @LastEditTime: 2023-07-14 10:04:32
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \app-customized\src\App.vue
-->
<template>
  <div class="web-app">
      <keep-alive>
        <router-view v-if="$route.meta.keepAlive"></router-view>
      </keep-alive>
      <router-view v-if="!$route.meta.keepAlive"></router-view>
  </div>
</template>

<script>
import YouXin from 'youxin-js-sdk';
import { mapMutations } from 'vuex';
import { HOME_MUTATION_TYPES } from '@/store';
import { baseServices } from '@/api';
import { set_content_security_policy } from '@/utils';
export default {
    created () {
    // this.getOrign();
  },
    methods: {
    ...mapMutations({
      SET_TAB: HOME_MUTATION_TYPES.SET_TAB
    }),
    async getOrign () {
      const platForm = 'plat_form', // 平台标识
        nationalPortal = 'national_portal', // 全国域名
        playSysvoddUrl = 'play_sysvodd_url', // 系统资源播放域名
        playLocalvoddUrl = 'play_localvodd_url', // 本地资源播放域名
        res = await baseServices.getStaticProtalJson(),
        domainList = (res.adjuction || {}).domainList || [],
        flatform = domainList.find(item => item.key === platForm) || {},
        NATIONAL_PORTAL_Domain = domainList.find(item => item.key === nationalPortal) || {},
        PLAY_SYSVODD_URL = domainList.find(item => item.key === playSysvoddUrl) || {},
        PLAY_LOCALVODD_URL = domainList.find(item => item.key === playLocalvoddUrl) || {},
        DOCTRANSTYPE = (res.adjuction || {}).docPreviewType || '',
        obj = {
          NATIONAL_PORTAL_Domain: `${NATIONAL_PORTAL_Domain.protocal}://${NATIONAL_PORTAL_Domain.host}`,
          Platform: flatform.host,
          play_sysvodd_url: `${PLAY_SYSVODD_URL.protocal}://${PLAY_SYSVODD_URL.host}`,
          play_localvodd_url: `${PLAY_LOCALVODD_URL.protocal}://${PLAY_LOCALVODD_URL.host}`,
          docPreviewType: DOCTRANSTYPE
        }, domain = JSON.stringify(obj);
      localStorage.setItem('loginDataMobile', domain);
      // this.addScriptToHead('operation/nboc/nboc_sdk/nbocSdk@1.0.js', () => { }, obj);
      this.addScriptToHead('nsdc/pv/bp/vcom-analytics-sdk.js', () => { }, obj);
      // this.addScriptToHead('nsdc/pv/bp/yj-utils.js', () => {}, obj);
    },
    addScriptToHead (href = 'operation/nboc/nboc_sdk/nbocSdk@1.0.js', fn, obj) {
      const iconLink = document.createElement('script');
      iconLink.type = 'text/javascript';
      const originHost = obj && obj.NATIONAL_PORTAL_Domain;
      iconLink.src = `${originHost}/${href}`;
      iconLink.onload = () => fn();
      document.getElementsByTagName('body')[0].appendChild(iconLink);
    }
  },
  mounted () {
    const _this = this;
    this.getOrign();
    YouXin.getNetworkStatus({
      success (row) {
        _this.isNetWord = !!row;
      }
    });
    YouXin.getStatusBarHeight({
      success (height) {
        _this.SET_TAB(height);
      }
    });
    // const local = sessionStorage.getItem('loginData') ? JSON.parse(sessionStorage.getItem('loginData')) : {};
    // if (!local.OSSDomain || local.OSSDomain === '') {
    //   this.$store.dispatch('setPlatform');
    // } else if (!local.Platform || local.Platform === '') {
    //   this.$store.dispatch('setPlatform');
    // }
    if (window.location.origin.split('//')[1].split(':')[0] === 'localhost') {
       window.hostOrigin = `https://cs.yjt361.com${process.env.VUE_APP_PATH_SOURCE}`;
    } else {
      window.hostOrigin = `${window.location.origin}${process.env.VUE_APP_PATH_SOURCE}`;
    }
    set_content_security_policy();
  }
};
</script>
<style>
html,body,.web-app,.flexBox{
  width:100%;
  height:100%
}
body{
  padding-bottom:constant(safe-area-inset-bottom);
}

</style>
